package com.zprmb.udzt.adapter;

import java.text.DecimalFormat;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.FundsBean;
import com.zprmb.udzt.util.Regular;

public class Funds_adapter extends BaseAdapter {
	private List<FundsBean> list;
	private Context context;
	DecimalFormat df = new DecimalFormat("###0.00");
	private String type;
	

	public Funds_adapter(List<FundsBean> list, Context context,
			 String type) {
		super();
		this.list = list;
		this.context = context;
		
		this.type = type;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.funds_item, null);
			h.tv_date=(TextView)convertView.findViewById(R.id.tv_date);
			h.tv_time=(TextView)convertView.findViewById(R.id.tv_time);
			h.tv_transaction_money=(TextView)convertView.findViewById(R.id.tv_transaction_money);
			h.tv_type=(TextView)convertView.findViewById(R.id.tv_type);
			h.tv_invest_status=(TextView)convertView.findViewById(R.id.invest_status);
			h.consumption_type=(TextView)convertView.findViewById(R.id.consumption_type);
			convertView.setTag(h);
		}else{
			h=(Help) convertView.getTag();
		}
		type=list.get(position).getOperationType();
		if(list.get(position).getOperationType().equals("DEPOSIT")||list.get(position).getOperationType().equals("WITHDRAW")||list.get(position).getOperationType().equals("APP_DEPOSIT")){
			h.tv_invest_status.setVisibility(View.VISIBLE);
		}else{
			h.tv_invest_status.setVisibility(View.GONE);
		}
		if(list.get(position).getOperationStatus().equals("IN")){
			h.tv_transaction_money.setTextColor(Color.parseColor("#ff0000"));
			h.tv_transaction_money.setText("+"+df.format(Double.parseDouble(list.get(position).getAmount()))+"元");
		}else{
			h.tv_transaction_money.setTextColor(Color.parseColor("#00D089"));
			if(type.equals("WITHDRAW")){
				h.tv_invest_status.setTextColor(Color.RED);
				h.tv_transaction_money.setText("-"+df.format(Double.parseDouble(list.get(position).getAmount()))+"元");

			}else{
				h.tv_invest_status.setTextColor(Color.BLACK);
				h.tv_transaction_money.setText("-"+df.format(Double.parseDouble(list.get(position).getAmount()))+"元");
			}
		}
		if(type.equals("WITHDRAW")){
			if(list.get(position).getOperationStatus().equals("OUT")){
				h.tv_transaction_money.setText("-"+df.format(Double.parseDouble(list.get(position).getAmount()))+"元");
			}else if(list.get(position).getOperationStatus().equals("RELEASE")){
				h.tv_transaction_money.setText("0.00元");
			}else if(list.get(position).getOperationStatus().equals("FREEZE")){
				h.tv_transaction_money.setText(df.format(Double.parseDouble(list.get(position).getAmount()))+"元");
			}
		}
		Log.e("vvv", list.get(position).getOperationType());
		h.tv_date.setText(Regular.getMilliToDate(list.get(position).getRecordTime()));
		h.tv_time.setText(Regular.getMilliTotime(list.get(position).getRecordTime()));
		
		h.tv_type.setText(list.get(position).getDescription());
		h.tv_invest_status.setText(list.get(position).getTradeStatusKey());
		h.consumption_type.setText(list.get(position).getOperationTypeKey());
		// TODO Auto-generated method stub
		return convertView;
	}
	private static class Help{
		private TextView tv_date,tv_time,tv_type,tv_transaction_money,tv_invest_status,consumption_type;
	}

}
